﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TestListGenerator.Common
{
    /// <summary>
    /// Contains methods to help with tests
    /// </summary>
    public class TestHelper
    {
        /// <summary>
        /// Checks to see if an exception matches the expected
        /// type, and if not, fails the test
        /// </summary>
        /// <param name="expected">The expected exception type</param>
        /// <param name="ex">The actual exception</param>
        public static void CheckException(Type expected, Exception ex)
        {
            CheckException(expected, ex, "The type of exception thrown wasn't correct.");
        }

        /// <summary>
        /// Checks to see if an exception matches the expected
        /// type, and if not, fails the test
        /// </summary>
        /// <param name="expected">The expected exception type</param>
        /// <param name="ex">The actual exception</param>
        /// <param name="errorMessage">The error message to return if the exception wasn't the correct one</param>
        public static void CheckException(Type expected, Exception ex, string errorMessage)
        {
            if (ex == null)
            {
                Assert.Fail("The exception was null. This is very weird considering this call should only be made in a catch statement");
            }

            // Check if the exception was of the right type
            Assert.AreEqual(expected, ex.GetType(), errorMessage + " Exception was: " + Dumper.Dump(ex));
        }
    }
}
